package com.nave.princesslife.header;


public class Princess_StateMachine implements Runnable {

	private static Princess_StateMachine instance;

	private Princess_StateMachine() {

		running = true;

		startTimeHappiness = System.currentTimeMillis();
		startTimeHunger = System.currentTimeMillis();
		startTimeSleep = System.currentTimeMillis();

		Thread thread = new Thread(this);
		thread.setPriority(Thread.MIN_PRIORITY);
		thread.start();
	}

	public static Princess_StateMachine getInstance() {
		if (instance == null)
			instance = new Princess_StateMachine();

		return instance;
	}

	private float happiness = 100;
	private float hunger = 100;
	private float sleep = 100;

	private boolean running;

	private long startTimeHappiness;
	private long startTimeHunger;
	private long startTimeSleep;
	private long currentTime;

	private float timeInSeconds_Happiness;
	private float timeInSeconds_Hunger;
	private float timeInSeconds_Sleep;

	private final float DECREASENUMBER = 0.166f;
	private final int MINUTE = 60;

	@Override
	public void run() {
		while (running) {

			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			currentTime = System.currentTimeMillis();

			timeInSeconds_Happiness = (currentTime - startTimeHappiness) / 1000L;
			timeInSeconds_Hunger = (currentTime - startTimeHunger) / 1000L;
			timeInSeconds_Sleep = (currentTime - startTimeSleep) / 1000L;

			// Se passou 60 segundos, diminuir a barra
			if (timeInSeconds_Happiness >= MINUTE) {

				if (happiness - DECREASENUMBER >= 0)
					happiness -= DECREASENUMBER;
				else
					happiness = 0;
				
				startTimeHappiness = currentTime;
			}
		}
	}

	public void draw() {

	}
}